package com.jfinal.controller;

import com.jfinal.aop.Clear;
import com.jfinal.constant.Const;
import com.jfinal.core.Controller;

import java.util.UUID;

/**
 * Created by xiaoyuan on 2018/1/19.
 */
@Clear
public class LoginController extends Controller {
    public void index(){
        String session_token = getSessionAttr(Const.SESSION_TOKEN);
        String lastRequestUrl = getPara("forwardURL");
        //判断是否已经登陆
        if(session_token!=null&&!session_token.isEmpty()){
            //已经登陆
        }else{
            //开启登陆逻辑（可以返回个登陆界面）
            //设置token
            setSessionAttr(Const.SESSION_TOKEN, UUID.randomUUID().toString());
            setSessionAttr(Const.SESSION_ROLES_ID,"1,2");
            System.out.println("登录成功");
        }
        if(lastRequestUrl!=null&&!lastRequestUrl.isEmpty()){
            redirect(lastRequestUrl);
        }else{
            //跳到默认主页
            redirect("/hello");
        }
    }
}
